package org.autocode.component;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import jdk.nashorn.internal.objects.annotations.Getter;
import jdk.nashorn.internal.objects.annotations.Setter;

import java.io.IOException;
import java.io.InputStream;

/**
 * @program: autocode
 * @description:
 * @author: zhu.xiaojie
 * @create: 2020-08-16 16:04
 */
public class IconLabel extends HBox {
    @FXML
    public ImageView icon;
    @FXML
    public Label label;

    private Type type;

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public IconLabel() {
        FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("fxml/IconLabel.fxml"));
        loader.setRoot(this);
        loader.setController(this);
        try {
            loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setText(String text){
        label.setText(text);
    }

    public void setIcon(InputStream in){
        Image image = new Image(in);
        icon.setImage(image);
    }
    public void setIcon(String path){
        try(InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path)){
            Image image = new Image(inputStream);
            icon.setImage(image);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public String getText(){
        return label.getText();
    }

    public static enum Type{
        INSTANCE,DATABASE,TABLE
    }
}
